﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using W_Fish.Models;

namespace W_Fish.Controllers
{
    public class AdminController : Controller
    {
        FishManagement_Timkiemx db = new FishManagement_Timkiemx();

        private static string USER;
        //
        // GET: /Admin/
        #region[MainAdmin]
        public ActionResult MainAdmin( string user)
        {
            ViewBag.l1a = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
            ViewBag.l1b = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
            ViewBag.l1c = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
            ViewBag.l1d = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
            ViewBag.l1e = "/Admin/AddPCOFG?id_each=-1&&id_all=5&&user=" + user;
            ViewBag.l1f = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.l2 = "/Admin/AddFish?id_fi=-1&&user=" + user;
            
            ViewBag.l3 = "/Admin/ChangInfo?user=" + user;
            ViewBag.l4 = "/Admin/ChangeInfo?user=" + user;
            
            ViewBag.l5 = "/Admin/ListView?evi=-1&&id_View=1&&ttd=1&&user=" + user;
            ViewBag.l6 = "/Admin/ListView?evi=-1&&id_View=2&&ttd=1&&user=" + user;
            ViewBag.l7 = "/Admin/ListView?evi=-1&&id_View=3&&ttd=1&&user=" + user;
            ViewBag.l8 = "/Admin/ListView?evi=-1&&id_View=4&&ttd=1&&user=" + user;
            ViewBag.l9 = "/Admin/ListView?evi=-1&&id_View=5&&ttd=1&&user=" + user;
            ViewBag.l10 = "/Admin/ListView?evi=-1&&id_View=6&&ttd=1&&user=" + user;
           
           
            ViewBag.l13 = "/Admin/ListView?evi=3&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l14 = "/Admin/ListView?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l15 = "/Admin/ListView?evi=1&&id_View=-1&&ttd=1&&user=" + user;
            
            ViewBag.l16 = "/Admin/MainAdmin?user=" + user;
            
            ViewBag.l17 = "/Admin/Poster?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l18 = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.AdminName = user;

            string chuoi = "";
            int i = 1;

            var Ph = (from _ph in db.Phyla where _ph.Ph_kiemduyet == false orderby _ph.Ph_Date descending select _ph).ToList<Phylum>();
            var Cl = (from _cl in db.ClassFish  where _cl.Cl_kiemduyet == false orderby _cl.Cl_Date descending select _cl).ToList<ClassFish>();
            var Or = (from _or in db.Ordoes where _or.Or_kiemduyet == false orderby _or.Or_Date descending select _or).ToList<Ordo>();
            var Fa = (from _fa in db.Familias where _fa.Fa_kiemduyet == false orderby _fa.Fa_Date descending select _fa).ToList<Familia>();
            var Ge = (from _ge in db.Genus where _ge.Ge_kiemduyet== false orderby _ge.Ge_Date descending select _ge).ToList<Genu>();
            var Fi = (from _fi in db.Fish where _fi.Fi_kiemduyet == false orderby _fi.Fi_Date descending select _fi).ToList<Fish>();

            foreach (Phylum a in Ph)
            {
                
                chuoi += "<tr> ";
                chuoi += "<td> " + i + ". </td> ";
                chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.PhylumID + "&&id_all=1&&user=" + user + "\">" + a.PhylumName + "</a></td> ";
                chuoi += "<td  style=\"text-align:right\">" + a.Ph_Date + "</td> ";
                chuoi += "<td  style=\"text-align:right\" >Chưa duyệt</td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.PhylumID + "&&id_all=1&&user=" + user + "\">Sửa</a></td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"Admin/Delete?type=1&&id=" + a.PhylumID + "&&name=\"x\"&&user=" + user + "\">Xóa</a></td> ";
                chuoi += "<td  style=\"text-align:center\"><input type=\"checkbox\" name=\"kiemduyet\"/></td>";
                chuoi += "</tr> ";
                i++;
            }

            foreach (ClassFish a in Cl)
            {
                
                chuoi += "<tr> ";
                chuoi += "<td> " + i + ". </td> ";
                chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.ClassID + "&&id_all=2&&user=" + user + "\">" + a.ClassName + "</a></td> ";
                chuoi += "<td  style=\"text-align:right\">" + a.Cl_Date + "</td> ";
                chuoi += "<td  style=\"text-align:right\">Chưa duyệt</td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.ClassID + "&&id_all=2&&user=" + user + "\">Sửa</a></td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"Admin/Delete?type=2&&id=" + a.ClassID + "&&name=\"x\"&&user=" + user + "\">Xóa</a></td> ";
                chuoi += "<td  style=\"text-align:center\"><input type=\"checkbox\" name=\"kiemduyet\"/></td>";
                chuoi += "</tr> ";
                i++;
            }


            foreach (Ordo a in Or)
            {
               
                chuoi += "<tr> ";
                chuoi += "<td> " + i + ". </td> ";
                chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.OrdoID + "&&id_all=3&&user=" + user + "\">" + a.OrdoName + "</a></td> ";
                chuoi += "<td  style=\"text-align:right\">" + a.Or_Date + "</td> ";
                chuoi += "<td  style=\"text-align:right\">Chưa duyệt</td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.OrdoID + "&&id_all=3&&user=" + user + "\">Sửa</a></td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"Admin/Delete?type=3&&id=" + a.OrdoID + "&&name=\"x\"&&user=" + user + "\">Xóa</a></td> ";
                chuoi += "<td  style=\"text-align:center\"><input type=\"checkbox\" name=\"kiemduyet\"/></td>";
                chuoi += "</tr> ";
                i++;
            }

            foreach (Familia a in Fa)
            {
                chuoi += "<tr> ";
                chuoi += "<td> " + i + ". </td> ";
                chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.FamiliaID + "&&id_all=4&&user=" + user + "\">" + a.FamilialName + "</a></td> ";
                chuoi += "<td  style=\"text-align:right\">" + a.Fa_Date + "</td> ";
                chuoi += "<td  style=\"text-align:right\">Chưa duyệt</td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.FamiliaID + "&&id_all=4&&user=" + user + "\">Sửa</a></td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"Admin/Delete?type=4&&id=" + a.FamiliaID + "&&name=\"x\"&&user=" + user + "\">Xóa</a></td> ";
                chuoi += "<td  style=\"text-align:center\"><input type=\"checkbox\" name=\"kiemduyet\"/></td>";
                chuoi += "</tr> ";
                i++;
            }


            foreach (Genu a in Ge)
            {
                chuoi += "<tr> ";
                chuoi += "<td> " + i + ". </td> ";
                chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.GenusID + "&&id_all=5&&user=" + user + "\">" + a.GenusName + "</a></td> ";
                chuoi += "<td  style=\"text-align:right\">" + a.Ge_Date + "</td> ";
                chuoi += "<td  style=\"text-align:right\">Chưa duyệt</td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.GenusID + "&&id_all=5&&user=" + user + "\">Sửa</a></td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"Admin/Delete?type=5&&id=" + a.GenusID + "&&name=\"x\"&&user=" + user + "\">Xóa</a></td> ";
                chuoi += "<td  style=\"text-align:center\"><input type=\"checkbox\" name=\"kiemduyet\"/></td>";
                chuoi += "</tr> ";
                i++;
            }

            foreach (Fish a in Fi)
            {              
                chuoi += "<tr> ";
                chuoi += "<td> " + i + ". </td> ";
                chuoi += "<td><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&user=" + user + "\">" + a.FishName + "</a></td> ";
                chuoi += "<td  style=\"text-align:right\">" + a.Fi_Date + "</td> ";
                chuoi += "<td  style=\"text-align:right\">Chưa duyệt</td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&id_all=1&&user=" + user + "\">Sửa</a></td> ";
                chuoi += "<td  style=\"text-align:right\"><a href=\"Admin/Delete?type=6&&id=" + a.FishID + "&&name=\"x\"&&user=" + user + "\">Xóa</a></td> ";
                chuoi += "<td  style=\"text-align:center\"><input type=\"checkbox\" name=\"kiemduyet\"/></td>";
                chuoi += "</tr> ";
                i++;
            }
            ViewBag.body = chuoi;
            return View();
           
        }

        [HttpPost]

        public ActionResult MainAdmin(FormCollection collection)
        {
            
            return View();
        }
        #endregion
        #region[AddPCOFG]
        public ActionResult AddPCOFG(int id_each, int id_all, string user)
        {
            ViewBag.l1a = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
            ViewBag.l1b = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
            ViewBag.l1c = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
            ViewBag.l1d = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
            ViewBag.l1e = "/Admin/AddPCOFG?id_each=-1&&id_all=5&&user=" + user;
            ViewBag.l1f = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.l2 = "/Admin/AddFish?id_fi=-1&&user=" + user;

            ViewBag.l3 = "/Admin/ChangInfo?user=" + user;
            ViewBag.l4 = "/Admin/ChangeInfo?user=" + user;

            ViewBag.l5 = "/Admin/ListView?evi=-1&&id_View=1&&ttd=1&&user=" + user;
            ViewBag.l6 = "/Admin/ListView?evi=-1&&id_View=2&&ttd=1&&user=" + user;
            ViewBag.l7 = "/Admin/ListView?evi=-1&&id_View=3&&ttd=1&&user=" + user;
            ViewBag.l8 = "/Admin/ListView?evi=-1&&id_View=4&&ttd=1&&user=" + user;
            ViewBag.l9 = "/Admin/ListView?evi=-1&&id_View=5&&ttd=1&&user=" + user;
            ViewBag.l10 = "/Admin/ListView?evi=-1&&id_View=6&&ttd=1&&user=" + user;


            ViewBag.l13 = "/Admin/ListView?evi=3&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l14 = "/Admin/ListView?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l15 = "/Admin/ListView?evi=1&&id_View=-1&&ttd=1&&user=" + user;

            ViewBag.l16 = "/Admin/MainAdmin?user=" + user;

            ViewBag.l17 = "/Admin/Poster?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l18 = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.AdminName = user;


            List<SelectListItem> dropdownItems = new List<SelectListItem>();

            switch (id_all)
            {
                case 1:
                    {
                        ViewBag.head = "Thêm ngành mới";
                        if(id_each>0)
                        {
                            Phylum cur = (from _cur in db.Phyla where _cur.PhylumID == id_each select _cur).ToList().First();
                            
                            ViewData["ten"] = cur.PhylumName;
                            ViewData["sinhhoc"] = cur.PhylumBiology;
                            ViewData["phanbo"] = cur.PhylumHabitat;
                        }
                        
                        break;
                    }
                case 2:
                    {
                       
                        
                        ViewBag.head = "Thêm lớp mới";
                        ViewBag.khac = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
                        var AllItem = (from a in db.Phyla where a.Ph_kiemduyet == true select a).ToList();
                        foreach (Phylum item in AllItem)
                        {
                            dropdownItems.Add(new SelectListItem() { Text = item.PhylumName, Value = item.PhylumID.ToString() });
                        }
                        if (id_each > 0)
                        {
                            ClassFish cur = (from _cur in db.ClassFish where _cur.ClassID == id_each select _cur).ToList().First();
                            ViewData["luachon"] = cur.IdPh;
                            ViewData["ten"] = cur.ClassName;
                            ViewData["sinhhoc"] = cur.ClassBiology;
                            ViewData["phanbo"] = cur.ClassHabitat;
                        }
                        
                        
                        break;
                    }
                case 3:
                    {
                       
                        ViewBag.khac = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
                        ViewBag.head = "Thêm bộ mới";
                        var AllItem = (from a in db.ClassFish where a.Cl_kiemduyet == true select a).ToList();
                        foreach (ClassFish item in AllItem)
                        {
                            dropdownItems.Add(new SelectListItem() { Text = item.ClassName, Value = item.ClassID.ToString() });
                        }

                        if (id_each > 0)
                        {
                            Ordo cur = (from _cur in db.Ordoes where _cur.OrdoID == id_each select _cur).ToList().First();
                            ViewData["luachon"] = cur.ClassID;
                            ViewData["ten"] = cur.OrdoName;
                            ViewData["sinhhoc"] = cur.OrdoBiology;
                            ViewData["phanbo"] = cur.OrdoHabitat;
                        }

                        break;
                    }
                case 4:
                    {
                        
                        ViewBag.khac = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
                        ViewBag.head = "Thêm họ mới";
                        var AllItem = (from a in db.Ordoes where a.Or_kiemduyet == true select a).ToList();
                        foreach (Ordo item in AllItem)
                        {
                            dropdownItems.Add(new SelectListItem() { Text = item.OrdoName, Value = item.OrdoID.ToString() });
                        }

                        if (id_each > 0)
                        {
                            Familia cur = (from _cur in db.Familias where _cur.FamiliaID == id_each select _cur).ToList().First();
                            ViewData["luachon"] = cur.OrdoID;
                            ViewData["ten"] = cur.FamilialName;
                            ViewData["sinhhoc"] = cur.FamilialBiology;
                            ViewData["phanbo"] = cur.FamilialHabitat;
                        }
                        break;

                    }
                case 5:
                    {
                       
                        ViewBag.khac = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
                        ViewBag.head = "Thêm chi mới";
                        var AllItem = (from a in db.Familias where a.Fa_kiemduyet == true select a).ToList();
                        foreach (Familia item in AllItem)
                        {
                            dropdownItems.Add(new SelectListItem() { Text = item.FamilialName, Value = item.FamiliaID.ToString() });
                        }

                        if (id_each > 0)
                        {
                            Genu cur = (from _cur in db.Genus where _cur.GenusID == id_each select _cur).ToList().First();
                            ViewData["luachon"] = cur.FamiliaID;
                            ViewData["ten"] = cur.GenusName;
                            ViewData["sinhhoc"] = cur.GenusBiology;
                            ViewData["phanbo"] = cur.GenusHabitat;
                        }
                        break;

                    }
                default:
                    {
                        break;
                    }
            }

            ViewData.Add("DropDownItems", dropdownItems);
            ID_ALL = id_all;
            ID_EACH = id_each;
            USER = user;
            return View();
        }

        static int ID_ALL;
        static int ID_EACH;
        [HttpPost]

        public ActionResult AddPCOFG(FormCollection collection)
        {
            int iluachon;
            try
            {
                iluachon = int.Parse(collection["luachon"]);
            }
            catch 
            {
                iluachon = 0;
            }
           
            string sh = collection["sinhhoc"];
            string pb = collection["phanbo"];
            string ten = collection["ten"];
            
            switch (ID_ALL)
            {
                case 1:
                    {
                        int max = 0;
                        var sph = (from _sph in db.Phyla select _sph).ToList();
                                               
                        Phylum Ph = new Phylum();
                        
                        Ph.PhylumName = ten;
                        Ph.PhylumBiology = sh;
                        Ph.PhylumHabitat = pb;
                        Ph.Ph_kiemduyet = true;
                        Ph.Ph_Sign = USER;
                        Ph.Ph_Date = DateTime.Now;
                        var p = (from _p in db.Phyla where _p.PhylumID == ID_EACH select _p).ToList();
                        if (p.Count == 0)
                        {
                            foreach (Phylum i in sph)
                            {
                                if (max < i.PhylumID) max = i.PhylumID;
                            }
                            Ph.PhylumID = max + 1;
                            db.Phyla.Add(Ph);
                            db.SaveChanges();

                        }
                        else 
                        {
                            p.First().PhylumName = ten;
                            p.First().PhylumBiology = sh;
                            p.First().PhylumHabitat = pb;
                            p.First().Ph_kiemduyet = true;
                            p.First().Ph_Sign = USER;
                            p.First().Ph_Date = DateTime.Now;
                            UpdateModel(p);
                            db.SaveChanges();
                        }
                        
                        break;
                    }
                case 2:
                    {
                        int max = 0;
                        var S = (from _s in db.ClassFish select _s).ToList();
                       
                        ClassFish Cl = new ClassFish();
                       
                        var p = (from _p in db.ClassFish where _p.ClassID == ID_EACH select _p).ToList();
                        
                        if (p.Count == 0)
                        {
                            Cl.ClassName = ten;
                            Cl.ClassBiology = sh;
                            Cl.ClassHabitat = pb;
                            Cl.Cl_Sign = USER;
                            Cl.Cl_kiemduyet = true;
                            Cl.Cl_Date = DateTime.Now;
                            Cl.IdPh = iluachon;
                            foreach (ClassFish i in S)
                            {
                                if (max < i.ClassID) max = i.ClassID;
                            }
                            Cl.ClassID = max + 1;
                            db.ClassFish.Add(Cl);

                        }
                        else
                        {
                            Cl = p.First();
                            Cl.ClassName = ten;
                            Cl.ClassBiology = sh;
                            Cl.ClassHabitat = pb;
                            Cl.Cl_Sign = USER;
                            Cl.Cl_kiemduyet = true;
                            Cl.Cl_Date = DateTime.Now;
                            Cl.IdPh = iluachon;
                            Cl.ClassID = ID_EACH;
                            UpdateModel(Cl);
                        }
                        break;
                    }
                case 3:
                    {
                        int max = 0;
                        var S = (from _s in db.Ordoes select _s).ToList();
                        
                        Ordo Cl = new Ordo();
                       
                        var p = (from _p in db.Ordoes where _p.OrdoID == ID_EACH select _p).ToList();
                       
                        if (p.Count == 0)
                        {
                            Cl.OrdoName = ten;
                            Cl.OrdoBiology = sh;
                            Cl.OrdoHabitat = pb;
                            Cl.Or_Sign = USER;
                            Cl.Or_kiemduyet = true;
                            Cl.Or_Date = DateTime.Now;
                            Cl.ClassID = iluachon;
                            foreach (Ordo i in S)
                            {
                                if (max < i.OrdoID) max = i.OrdoID;
                            }
                            Cl.OrdoID = max + 1;
                            db.Ordoes.Add(Cl);


                        }
                        else
                        {
                            Cl = p.First();
                            Cl.OrdoName = ten;
                            Cl.OrdoBiology = sh;
                            Cl.OrdoHabitat = pb;
                            Cl.Or_Sign = USER;
                            Cl.Or_kiemduyet = true;
                            Cl.Or_Date = DateTime.Now;
                            Cl.ClassID = iluachon;
                            Cl.ClassID = ID_EACH;
                            UpdateModel(Cl);
                        }

                        break;
                    }
                case 4:
                    {
                        int max = 0;
                        var S = (from _s in db.Familias select _s).ToList();
                       
                        Familia Cl = new Familia();

                        var p = (from _p in db.Familias where _p.FamiliaID == ID_EACH select _p).ToList();
                       
                        if (p.Count == 0)
                        {
                            Cl.FamilialName = ten;
                            Cl.FamilialBiology = sh;
                            Cl.FamilialHabitat = pb;
                            Cl.Fa_Sign = USER;
                            Cl.Fa_kiemduyet = true;
                            Cl.Fa_Date = DateTime.Now;
                            Cl.OrdoID = iluachon;
                            foreach (Familia i in S)
                            {
                                if (max < i.FamiliaID) max = i.FamiliaID;
                            }
                            Cl.FamiliaID = max + 1;
                            db.Familias.Add(Cl);


                        }
                        else
                        {
                            Cl = p.First();
                            Cl.FamilialName = ten;
                            Cl.FamilialBiology = sh;
                            Cl.FamilialHabitat = pb;
                            Cl.Fa_Sign = USER;
                            Cl.Fa_kiemduyet = true;
                            Cl.Fa_Date = DateTime.Now;
                            Cl.OrdoID = iluachon;
                            Cl.FamiliaID = ID_EACH;
                            UpdateModel(Cl);
                        }

                        break;

                    }
                case 5:
                    {
                        int max = 0;
                        var S = (from _s in db.Genus select _s).ToList();
                        
                        Genu Cl = new Genu();
                        
                        var p = (from _p in db.Genus where _p.GenusID == ID_EACH select _p).ToList();
                        
                        if (p.Count == 0)
                        {
                            Cl.GenusName = ten;
                            Cl.GenusBiology = sh;
                            Cl.GenusHabitat = pb;
                            Cl.Ge_Sign = USER;
                            Cl.Ge_kiemduyet = true;
                            Cl.Ge_Date = DateTime.Now;
                            Cl.FamiliaID = iluachon;
                            foreach (Genu i in S)
                            {
                                if (max < i.GenusID) max = i.GenusID;
                            }
                            Cl.GenusID = max + 1;
                            db.Genus.Add(Cl);

                        }
                        else
                        {
                            Cl = p.First();
                            Cl.GenusName = ten;
                            Cl.GenusBiology = sh;
                            Cl.GenusHabitat = pb;
                            Cl.Ge_Sign = USER;
                            Cl.Ge_kiemduyet = true;
                            Cl.Ge_Date = DateTime.Now;
                            Cl.FamiliaID = iluachon;
                            Cl.GenusID = ID_EACH;
                            UpdateModel(Cl);
                        }


                        break;

                    }
                default:
                    {
                        break;
                    }
            }
            db.SaveChanges();
            return RedirectToAction("ListView", new { evi = -1, id_View = ID_ALL, ttd = 1, user = USER });
        }

        #endregion
        #region[AddFish]
        public static int ID_FI;
        public ActionResult AddFish(int id_fi, string user)
        {
            ViewBag.l1a = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
            ViewBag.l1b = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
            ViewBag.l1c = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
            ViewBag.l1d = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
            ViewBag.l1e = "/Admin/AddPCOFG?id_each=-1&&id_all=5&&user=" + user;
            ViewBag.l1f = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.l2 = "/Admin/AddFish?id_fi=-1&&user=" + user;

            ViewBag.l3 = "/Admin/ChangInfo?user=" + user;
            ViewBag.l4 = "/Admin/ChangeInfo?user=" + user;

            ViewBag.l5 = "/Admin/ListView?evi=-1&&id_View=1&&ttd=1&&user=" + user;
            ViewBag.l6 = "/Admin/ListView?evi=-1&&id_View=2&&ttd=1&&user=" + user;
            ViewBag.l7 = "/Admin/ListView?evi=-1&&id_View=3&&ttd=1&&user=" + user;
            ViewBag.l8 = "/Admin/ListView?evi=-1&&id_View=4&&ttd=1&&user=" + user;
            ViewBag.l9 = "/Admin/ListView?evi=-1&&id_View=5&&ttd=1&&user=" + user;
            ViewBag.l10 = "/Admin/ListView?evi=-1&&id_View=6&&ttd=1&&user=" + user;


            ViewBag.l13 = "/Admin/ListView?evi=3&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l14 = "/Admin/ListView?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l15 = "/Admin/ListView?evi=1&&id_View=-1&&ttd=1&&user=" + user;

            ViewBag.l16 = "/Admin/MainAdmin?user=" + user;

            ViewBag.l17 = "/Admin/Poster?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l18 = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.AdminName = user;

            ViewBag.khac = "/PosterView/AddPCOFG?id_all=5&&user=" + user;
            List<SelectListItem> dropdownItems = new List<SelectListItem>();
            var AllItem = (from _allitem in db.Genus where _allitem.Ge_kiemduyet == true select _allitem).ToList<Genu>();
            foreach (Genu item in AllItem)
            {
                dropdownItems.Add(new SelectListItem() { Text = item.GenusName, Value = item.GenusID.ToString() });
            }
            ViewData.Add("DropDownItems1", dropdownItems);

            dropdownItems = new List<SelectListItem>();
            dropdownItems.AddRange(new[]{
                            new SelectListItem() { Text = "Nuoc ngot ", Value = "3" },
                            new SelectListItem() { Text = "Nuoc man", Value = "2" },
                            new SelectListItem() { Text = "Nuoc lo", Value = "1" },
            });
            ViewData.Add("DropDownItems2", dropdownItems);


            if (id_fi > 0)
            {
                var Fi = (from _fi in db.Fish where id_fi == _fi.FishID select _fi).ToList<Fish>();
                Fish a = Fi.First<Fish>();
                ViewData["FishName"] = a.FishName;
                ViewData["Mainname"] = a.MainName;
                ViewData["Nomerclature"] = a.Nomerclature;
                ViewData["NameVN"] = a.NameVN;
                ViewData["TOt_Min"] = a.TOt_Min;
                ViewData["TOt_Max"] = a.TOt_Max;
                ViewData["TOO_Min"] = a.TOO_Min;
                ViewData["TOO_Max"] = a.TOO_Max;
                ViewData["TO_Min"] = a.TO_Min;
                ViewData["TO_Max"] = a.TO_Max;
                ViewData["Tlcd_Min"] = a.Tlcd_Min;
                ViewData["Tlcd_Max"] = a.Tlcd_Max;
                ViewData["Tccd_Min"] = a.Tccd_Min;
                ViewData["Tccd_Max"] = a.Tccd_Max;
                ViewData["Scientific"] = a.Scientific;
                ViewData["Resourcce"] = a.Resourcce;
                ViewData["Reproduction"] = a.Reproduction;
                ViewData["PVVA_Min"] = a.PVVA_Min;
                ViewData["PVVA_Max"] = a.PVVA_Max;
                ViewData["OOO_Min"] = a.OOO_Min;
                ViewData["OOO_Max"] = a.OOO_Max;
                ViewData["Nutrition"] = a.Nutrition;
                ViewData["LoT_Min"] = a.LoT_Min;
                ViewData["LoT_Max"] = a.LoT_Max;
                ViewData["Lolcd_Min"] = a.Lolcd_Min;
                ViewData["Lolcd_Max"] = a.Lolcd_Max;
                ViewData["LoH_Min"] = a.LoH_Min;
                ViewData["LoH_Max"] = a.LoH_Max;
                ViewData["LodaD_Min"] = a.LodaD_Min;
                ViewData["LodaD_Max"] = a.LodaD_Max;
                ViewData["Loccd_Min"] = a.Loccd_Min;
                ViewData["Loccd_Max"] = a.Loccd_Max;
                ViewData["LivingHabit"] = a.LivingHabit;
                ViewData["LcmaxLcmin_Min"] = a.LcmaxLcmin_Min;
                ViewData["LcmaxLcmin_Max"] = a.LcmaxLcmin_Max;
                ViewData["lcdccd_Min"] = a.lcdccd_Min;
                ViewData["lcdccd_Max"] = a.lcdccd_Max;
                ViewData["Hh_Min"] = a.Hh_Min;
                ViewData["Hh_Max"] = a.Hh_Max;
                ViewData["Growth"] = a.Growth;
                ViewData["FishHabittatW"] = a.FishHabittatW;
                ViewData["FishHabitatVN"] = a.FishHabitatVN;
                ViewData["Economic"] = a.Economic;
                ViewData["moitruong"] = a.Environment;
                ViewData["luachon"] = a.GenusID;
                
                string[] allim = a.image.Split(new string[] {"[x]"}, StringSplitOptions.None);
                string ima = "";
                foreach (string x in allim)
                {
                    ima += "<img width=\"150\" height=\"100\" src = \"" + x + "\"/>";
                }
                ViewBag.Image = ima;
            }

            FI_ID = id_fi;
            USER = user;
            return View();
        }
        
        
        static int FI_ID;
        public int MAX = 100000;
        
        
        [HttpPost]
        public ActionResult AddFish(FormCollection collection)
        {
            
            int ID = 0;
            Boolean isupdate;
            var Fi = (from _fi in db.Fish where _fi.FishID == FI_ID select _fi).ToList();
            if (Fi.Count == 0)
            {
                isupdate = false;
            }
            else isupdate = true;

            var f = (from fi in db.Fish select fi).ToList();
            foreach (Fish f1 in f)
            {
                
                if (ID < f1.FishID) ID = f1.FishID;
            }
            Fish newfish = new Fish();
            
            
            if (isupdate == false)
            {

                newfish.Economic = collection["Economic"];
                newfish.Fi_Date = DateTime.Now;
                newfish.Fi_kiemduyet = true;
                newfish.Fi_Sign = "Poster1";
                newfish.FishHabitatVN = collection["FishHabitatVN"];
                newfish.FishHabittatW = collection["FishHabitatW"];
                newfish.FishName = collection["FishName"];
                newfish.GenusID = int.Parse(collection["luachon"]);
                newfish.Growth = collection["Growth"];

                newfish.NameVN = collection["NameVN"];
                newfish.Nomerclature = collection["Nomerclature"];
                newfish.Nutrition = collection["Nutrition"];
                newfish.Resourcce = collection["Resourcce"];
                try
                {
                    newfish.Hh_Max = float.Parse(collection["Hh_Max"]);
                }
                catch
                {
                    newfish.Hh_Max = MAX;
                }
                try { newfish.Hh_Min = float.Parse(collection["Hn_Min"]); }
                catch { newfish.Hh_Min = -1; }
                try { newfish.lcdccd_Max = float.Parse(collection["lcdccd_Max"]); }
                catch { newfish.lcdccd_Max = MAX; }
                try { newfish.LcmaxLcmin_Min = float.Parse(collection["LcmaxLcmin_Min"]); }
                catch { newfish.LcmaxLcmin_Min = -1; }
                try { newfish.Loccd_Max = float.Parse(collection["Loccd_Max"]); }
                catch { newfish.Loccd_Max = MAX; }
                try { newfish.Loccd_Min = float.Parse(collection["Loccd_Min"]); }
                catch { newfish.Loccd_Min = -1; }
                try { newfish.LodaD_Max = float.Parse(collection["LodaD_Max"]); }
                catch { newfish.LodaD_Max = MAX; }
                try { newfish.LodaD_Min = float.Parse(collection["LodaD_Min"]); }
                catch { newfish.LodaD_Min = -1; }
                try { newfish.LoH_Max = float.Parse(collection["LoH_Max"]); }
                catch { newfish.LoH_Max = MAX; }
                try { newfish.LoH_Min = float.Parse(collection["LoH_Min"]); }
                catch { newfish.LoH_Min = -1; }
                try { newfish.Lolcd_Max = float.Parse(collection["Lolcd_Max"]); }
                catch { newfish.Lolcd_Max = MAX; }
                try { newfish.Lolcd_Min = float.Parse(collection["Lolcd_Min"]); }
                catch { newfish.Lolcd_Min = -1; };
                try { newfish.LoT_Max = float.Parse(collection["LoT_Max"]); }
                catch { newfish.LoT_Max = MAX; }
                try { newfish.LoT_Min = float.Parse(collection["LoT_Min"]); }
                catch { newfish.LoT_Min = -1; }
                try { newfish.OOO_Max = float.Parse(collection["OOO_Max"]); }
                catch { newfish.OOO_Max = MAX; }
                try { newfish.OOO_Min = float.Parse(collection["OOO_Min"]); }
                catch { newfish.OOO_Min = -1; }
                try { newfish.PVVA_Max = float.Parse(collection["PVVA_Max"]); }
                catch { newfish.PVVA_Max = MAX; }
                try { newfish.PVVA_Min = float.Parse(collection["PVVA_Min"]); }
                catch { newfish.PVVA_Min = -1; }
                try { newfish.Tccd_Max = float.Parse(collection["Tccd_Max"]); }
                catch { newfish.Tccd_Max = MAX; }
                try { newfish.Tccd_Min = float.Parse(collection["Tccd_Min"]); }
                catch { newfish.Tccd_Min = -1; }
                try { newfish.Tlcd_Max = float.Parse(collection["Tlcd_Max"]); }
                catch { newfish.Tlcd_Max = MAX; }
                try { newfish.Tlcd_Min = float.Parse(collection["Tlcd_Min"]); }
                catch { newfish.Tlcd_Min = -1; }
                try { newfish.TO_Max = float.Parse(collection["TO_Max"]); }
                catch { newfish.TO_Max = MAX; }
                try { newfish.TO_Min = float.Parse(collection["TO_Min"]); }
                catch { newfish.TO_Min = -1; }
                try { newfish.TOO_Max = float.Parse(collection["TOO_Max"]); }
                catch { newfish.TOO_Max = MAX; }
                try { newfish.TOO_Min = float.Parse(collection["TOO_Min"]); }
                catch { newfish.TOO_Min = -1; }
                try { newfish.TOt_Max = float.Parse(collection["TOt_Max"]); }
                catch { newfish.TOt_Max = MAX; }
                try { newfish.TOt_Min = float.Parse(collection["TOt_Min"]); }
                catch { newfish.TOt_Min = -1; }
                string image = "";
                if (collection["image1"] != "")
                {
                    image = collection["image1"];
                }
                if (collection["image2"] != "")
                {
                    image += "[x]" + collection["image2"];
                }
                if (collection["image3"] != "")
                {
                    image += "[x]" + collection["image3"];
                }
                if (collection["image4"] != "")
                {
                    image += "[x]" + collection["image4"];
                }
                if (collection["image5"] != "")
                {
                    image += "[x]" + collection["image5"];
                }
                newfish.image = image;
                
                newfish.Fi_Sign = USER;
                newfish.Environment = int.Parse(collection["moitruong"]);          
                newfish.FishID = ID + 1;
                db.Fish.Add(newfish); 
            }
            else
            {
                newfish = Fi.First();
                newfish.Economic = collection["Economic"];
                newfish.Fi_Date = DateTime.Now;
                newfish.Fi_kiemduyet = true;
                newfish.Fi_Sign = "Poster1";
                newfish.FishHabitatVN = collection["FishHabitatVN"];
                newfish.FishHabittatW = collection["FishHabitatW"];
                newfish.FishName = collection["FishName"];
                newfish.GenusID = int.Parse(collection["luachon"]);
                newfish.Growth = collection["Growth"];

                newfish.NameVN = collection["NameVN"];
                newfish.Nomerclature = collection["Nomerclature"];
                newfish.Nutrition = collection["Nutrition"];
                newfish.Resourcce = collection["Resourcce"];
                try
                {
                    newfish.Hh_Max = float.Parse(collection["Hh_Max"]);
                }
                catch
                {
                    newfish.Hh_Max = MAX;
                }
                try { newfish.Hh_Min = float.Parse(collection["Hn_Min"]); }
                catch { newfish.Hh_Min = -1; }
                try { newfish.lcdccd_Max = float.Parse(collection["lcdccd_Max"]); }
                catch { newfish.lcdccd_Max = MAX; }
                try { newfish.LcmaxLcmin_Min = float.Parse(collection["LcmaxLcmin_Min"]); }
                catch { newfish.LcmaxLcmin_Min = -1; }
                try { newfish.Loccd_Max = float.Parse(collection["Loccd_Max"]); }
                catch { newfish.Loccd_Max = MAX; }
                try { newfish.Loccd_Min = float.Parse(collection["Loccd_Min"]); }
                catch { newfish.Loccd_Min = -1; }
                try { newfish.LodaD_Max = float.Parse(collection["LodaD_Max"]); }
                catch { newfish.LodaD_Max = MAX; }
                try { newfish.LodaD_Min = float.Parse(collection["LodaD_Min"]); }
                catch { newfish.LodaD_Min = -1; }
                try { newfish.LoH_Max = float.Parse(collection["LoH_Max"]); }
                catch { newfish.LoH_Max = MAX; }
                try { newfish.LoH_Min = float.Parse(collection["LoH_Min"]); }
                catch { newfish.LoH_Min = -1; }
                try { newfish.Lolcd_Max = float.Parse(collection["Lolcd_Max"]); }
                catch { newfish.Lolcd_Max = MAX; }
                try { newfish.Lolcd_Min = float.Parse(collection["Lolcd_Min"]); }
                catch { newfish.Lolcd_Min = -1; };
                try { newfish.LoT_Max = float.Parse(collection["LoT_Max"]); }
                catch { newfish.LoT_Max = MAX; }
                try { newfish.LoT_Min = float.Parse(collection["LoT_Min"]); }
                catch { newfish.LoT_Min = -1; }
                try { newfish.OOO_Max = float.Parse(collection["OOO_Max"]); }
                catch { newfish.OOO_Max = MAX; }
                try { newfish.OOO_Min = float.Parse(collection["OOO_Min"]); }
                catch { newfish.OOO_Min = -1; }
                try { newfish.PVVA_Max = float.Parse(collection["PVVA_Max"]); }
                catch { newfish.PVVA_Max = MAX; }
                try { newfish.PVVA_Min = float.Parse(collection["PVVA_Min"]); }
                catch { newfish.PVVA_Min = -1; }
                try { newfish.Tccd_Max = float.Parse(collection["Tccd_Max"]); }
                catch { newfish.Tccd_Max = MAX; }
                try { newfish.Tccd_Min = float.Parse(collection["Tccd_Min"]); }
                catch { newfish.Tccd_Min = -1; }
                try { newfish.Tlcd_Max = float.Parse(collection["Tlcd_Max"]); }
                catch { newfish.Tlcd_Max = MAX; }
                try { newfish.Tlcd_Min = float.Parse(collection["Tlcd_Min"]); }
                catch { newfish.Tlcd_Min = -1; }
                try { newfish.TO_Max = float.Parse(collection["TO_Max"]); }
                catch { newfish.TO_Max = MAX; }
                try { newfish.TO_Min = float.Parse(collection["TO_Min"]); }
                catch { newfish.TO_Min = -1; }
                try { newfish.TOO_Max = float.Parse(collection["TOO_Max"]); }
                catch { newfish.TOO_Max = MAX; }
                try { newfish.TOO_Min = float.Parse(collection["TOO_Min"]); }
                catch { newfish.TOO_Min = -1; }
                try { newfish.TOt_Max = float.Parse(collection["TOt_Max"]); }
                catch { newfish.TOt_Max = MAX; }
                try { newfish.TOt_Min = float.Parse(collection["TOt_Min"]); }
                catch { newfish.TOt_Min = -1; }
                string image = "";
                if (collection["image1"] != "")
                {
                    image = newfish.image + "[x]" + collection["image1"];
                }
                if (collection["image2"] != "")
                {
                    image += "[x]" + collection["image2"];
                }
                if (collection["image3"] != "")
                {
                    image += "[x]" + collection["image3"];
                }
                if (collection["image4"] != "")
                {
                    image += "[x]" + collection["image4"];
                }
                if (collection["image5"] != "")
                {
                    image += "[x]" + collection["image5"];
                }
                newfish.Fi_Sign = USER;
                newfish.Environment = int.Parse(collection["moitruong"]);
                newfish.image = image;
                newfish.FishID = FI_ID;
                UpdateModel(newfish);
            }
                db.SaveChanges();
            return RedirectToAction("ListView", new {evi = -1, id_View = 6, ttd = 2, user = USER });
        }
        #endregion  //ok
        #region [ListView]
        /// <summary>
        /// Hiển thị dạnh sách loài, lớp, bộ, họ, chi,loài, ngành. dưới hình thức lựa chọn= > submit => View list danh sách
        /// Với mỗi một đối tượng trong danh sách có các lựa chọn xóa, update. Ngoài ra còn chức năng thêm mới.
        /// </summary>
        /// <param name="id_View"> 0,1,2,3,4,5 tương ứng với ngành, lớp, bộ, họ, chi, loài</param>
        /// <returns> </returns>
        public ActionResult ListView(int evi, int id_View, int ttd, string user)
        {
            ViewBag.l1a = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
            ViewBag.l1b = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
            ViewBag.l1c = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
            ViewBag.l1d = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
            ViewBag.l1e = "/Admin/AddPCOFG?id_each=-1&&id_all=5&&user=" + user;
            ViewBag.l1f = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.l2 = "/Admin/AddFish?id_fi=-1&&user=" + user;

            ViewBag.l3 = "/Admin/ChangInfo?user=" + user;
            ViewBag.l4 = "/Admin/ChangeInfo?user=" + user;

            ViewBag.l5 = "/Admin/ListView?evi=-1&&id_View=1&&ttd=1&&user=" + user;
            ViewBag.l6 = "/Admin/ListView?evi=-1&&id_View=2&&ttd=1&&user=" + user;
            ViewBag.l7 = "/Admin/ListView?evi=-1&&id_View=3&&ttd=1&&user=" + user;
            ViewBag.l8 = "/Admin/ListView?evi=-1&&id_View=4&&ttd=1&&user=" + user;
            ViewBag.l9 = "/Admin/ListView?evi=-1&&id_View=5&&ttd=1&&user=" + user;
            ViewBag.l10 = "/Admin/ListView?evi=-1&&id_View=6&&ttd=1&&user=" + user;


            ViewBag.l13 = "/Admin/ListView?evi=3&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l14 = "/Admin/ListView?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l15 = "/Admin/ListView?evi=1&&id_View=-1&&ttd=1&&user=" + user;

            ViewBag.l16 = "/Admin/MainAdmin?user=" + user;

            ViewBag.l17 = "/Admin/Poster?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l18 = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.AdminName = user;

            List<SelectListItem> dropdownItems = new List<SelectListItem>();
            dropdownItems.AddRange(new[]{
                            new SelectListItem() { Text = " Theo Tên", Value = "1"},
                            new SelectListItem() { Text = "Ngày cập nhật", Value = "2" },});
            ViewData.Add("DropDownItems", dropdownItems);

            string chuoi = "";
            if (ttd == 1)
            {
                if (evi == -1)
                {
                    switch (id_View)
                    {
                        case 1:
                            {
                                ViewBag.head = "Danh sách ngành";
                                var Ph = (from _ph in db.Phyla orderby _ph.PhylumName select _ph).ToList<Phylum>();
                                int i = 1;
                                foreach (Phylum a in Ph)
                                {
                                    string kiemduyet;
                                    if (a.Ph_kiemduyet == true) kiemduyet ="Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.PhylumID + "&&id_all=1&&user=" + user + "\">" + a.PhylumName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Ph_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\" >" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each="+a.PhylumID+"&&id_all=1&&user="+user+"\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=1&&id="+a.PhylumID+"&&name=&&user="+user+"\">Xóa</a></td> ";                                  
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 2:
                            {
                                ViewBag.head = "Danh sách lớp";
                                var Cl = (from _cl in db.ClassFish orderby _cl.ClassName select _cl).ToList<ClassFish>();
                                int i = 1;
                                foreach (ClassFish a in Cl)
                                {
                                    string kiemduyet;
                                    if (a.Cl_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.ClassID + "&&id_all=2&&user=" + user + "\">" + a.ClassName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Cl_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.ClassID + "&&id_all=2&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=2&&id=" + a.ClassID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 3:
                            {
                                ViewBag.head = "Danh sách bộ";
                                var Or = (from _or in db.Ordoes orderby _or.OrdoName select _or).ToList<Ordo>();
                                int i = 1;
                                foreach (Ordo a in Or)
                                {
                                    string kiemduyet;
                                    if (a.Or_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.OrdoID + "&&id_all=3&&user=" + user + "\">" + a.OrdoName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Or_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.OrdoID + "&&id_all=3&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=3&&id=" + a.OrdoID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 4:
                            {
                                
                                ViewBag.head = "Danh sách họ";
                                var Fa = (from _fa in db.Familias orderby _fa.FamilialName select _fa).ToList<Familia>();
                                int i = 1;
                                foreach (Familia a in Fa)
                                {
                                    string kiemduyet;
                               
                                    if (a.Fa_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.FamiliaID + "&&id_all=4&&user=" + user + "\">" + a.FamilialName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Fa_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.FamiliaID + "&&id_all=4&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=4&&id=" + a.FamiliaID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 5:
                            {
                                ViewBag.head = "Danh sách chi";
                                var Ge = (from _ge in db.Genus orderby _ge.GenusName select _ge).ToList<Genu>();
                                int i = 1;
                                foreach (Genu a in Ge)
                                {
                                    string kiemduyet;

                                    if (a.Ge_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.GenusID + "&&id_all=5&&user=" + user + "\">" + a.GenusName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Ge_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.GenusID + "&&id_all=5&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=5&&id=" + a.GenusID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 6:
                            {
                                ViewBag.head = "Danh sách loài cá";
                                var Fi = (from _fi in db.Fish orderby _fi.FishName select _fi).ToList<Fish>();
                                int i = 1;
                                foreach (Fish a in Fi)
                                {
                                    string kiemduyet;

                                    if (a.Fi_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&user=" + user + "\">" + a.FishName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Fi_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&id_all=1&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=6&&id=" + a.FishID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        default: break;
                    }
                }
                else
                {
                    if (evi == 1) ViewBag.head = "Danh sách cá sống nước lợ";
                    if (evi == 2) ViewBag.head = "Danh sách cá nước mặn";
                    if (evi == 3) ViewBag.head = "Danh sách cá nước ngọt";
                    var Fi = (from _fi in db.Fish where _fi.Environment == evi orderby _fi.FishName select _fi).ToList<Fish>();
                    int i = 1;
                    foreach (Fish a in Fi)
                    {
                        string kiemduyet;
                        if (a.Fi_kiemduyet == true) kiemduyet = "Đã duyệt";
                        else kiemduyet = "Chưa duyệt";
                        chuoi += "<tr> ";
                        chuoi += "<td> " + i + ". </td> ";
                        chuoi += "<td><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&user=" + user + "\">" + a.FishName + "</a></td> ";
                        chuoi += "<td  style=\"text-align:right\">" + a.Fi_Date + "</td> ";
                        chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                        chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&id_all=1&&user=" + user + "\">Sửa</a></td> ";
                        chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=6&&id=" + a.FishID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                        chuoi += "</tr> ";
                        i++;
                    }
                }

            }
            if (ttd == 2)
            {
                if (evi == -1)
                {
                    switch (id_View)
                    {
                        case 1:
                            {
                                ViewBag.head = "Danh sách ngành";
                                var Ph = (from _ph in db.Phyla orderby _ph.Ph_Date descending select _ph).ToList<Phylum>();
                                int i = 1;
                                foreach (Phylum a in Ph)
                                {
                                    string kiemduyet;
                                    if (a.Ph_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.PhylumID + "&&id_all=1&&user=" + user + "\">" + a.PhylumName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Ph_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.PhylumID + "&&id_all=1&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=1&&id=" + a.PhylumID + "&&name=&&user=" + user + "\">Xóa</a></td> ";                                  
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 2:
                            {
                                ViewBag.head = "Danh sách lớp";
                                var Cl = (from _cl in db.ClassFish orderby _cl.Cl_Date descending select _cl).ToList<ClassFish>();
                                int i = 1;
                                foreach (ClassFish a in Cl)
                                {
                                    string kiemduyet;
                                    if (a.Cl_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.ClassID + "&&id_all=2&&user=" + user + "\">" + a.ClassName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Cl_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.ClassID + "&&id_all=2&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=2&&id=" + a.ClassID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 3:
                            {
                                ViewBag.head = "Danh sách bộ";
                                
                                var Or = (from _or in db.Ordoes orderby _or.Or_Date descending select _or).ToList<Ordo>();
                                int i = 1;
                                foreach (Ordo a in Or)
                                {
                                    string kiemduyet;
                                    if (a.Or_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.OrdoID + "&&id_all=3&&user=" + user + "\">" + a.OrdoName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Or_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.OrdoID + "&&id_all=3&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=3&&id=" + a.OrdoID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 4:
                            {
                                ViewBag.head = "Danh sách họ";
                                
                                var Fa = (from _fa in db.Familias orderby _fa.Fa_Date descending select _fa).ToList<Familia>();
                                int i = 1;
                                foreach (Familia a in Fa)
                                {
                                    string kiemduyet;

                                    if (a.Fa_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.FamiliaID + "&&id_all=4&&user=" + user + "\">" + a.FamilialName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Fa_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.FamiliaID + "&&id_all=4&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=4&&id=" + a.FamiliaID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 5:
                            {
                                ViewBag.head = "Danh sách chi";
                                
                                var Ge = (from _ge in db.Genus orderby _ge.Ge_Date descending select _ge).ToList<Genu>();
                                int i = 1;
                                foreach (Genu a in Ge)
                                {
                                    string kiemduyet;

                                    if (a.Ge_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddPCOFG?id_each=" + a.GenusID + "&&id_all=5&&user=" + user + "\">" + a.GenusName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Ge_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddPCOFG?id_each=" + a.GenusID + "&&id_all=5&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=5&&id=" + a.GenusID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        case 6:
                            {
                                ViewBag.head = "Danh sách loài cá";
                                
                                var Fi = (from _fi in db.Fish orderby _fi.Fi_Date descending select _fi).ToList<Fish>();
                                int i = 1;
                                foreach (Fish a in Fi)
                                {
                                    string kiemduyet;

                                    if (a.Fi_kiemduyet == true) kiemduyet = "Đã duyệt";
                                    else kiemduyet = "Chưa duyệt";
                                    chuoi += "<tr> ";
                                    chuoi += "<td> " + i + ". </td> ";
                                    chuoi += "<td><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&user=" + user + "\">" + a.FishName + "</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + a.Fi_Date + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&id_all=1&&user=" + user + "\">Sửa</a></td> ";
                                    chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=6&&id=" + a.FishID + "&&name=&&user=" + user + "\">Xóa</a></td> "; 
                                    chuoi += "</tr> ";
                                    i++;
                                }
                                break;
                            }
                        default: break;
                    }
                }
                else
                {
                    if (evi == 1) ViewBag.head = "Danh sách cá sống nước lợ";
                    if (evi == 2) ViewBag.head = "Danh sách cá nước mặn";
                    if (evi == 3) ViewBag.head = "Danh sách cá nước ngọt";
                    var Fi = (from _fi in db.Fish where _fi.Environment == evi orderby _fi.Fi_Date descending select _fi).ToList<Fish>();
                    int i = 1;
                    foreach (Fish a in Fi)
                    {
                        string kiemduyet;
                        if (a.Fi_kiemduyet == true) kiemduyet = "Đã duyệt";
                        else kiemduyet = "Chưa duyệt";
                        chuoi += "<tr> ";
                        chuoi += "<td> " + i + ". </td> ";
                        chuoi += "<td><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&user=" + user + "\">" + a.FishName + "</a></td> ";
                        chuoi += "<td  style=\"text-align:right\">" + a.Fi_Date + "</td> ";
                        chuoi += "<td  style=\"text-align:right\">" + kiemduyet + "</td> ";
                        chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/AddFish?id_fi=" + a.FishID + "&&id_all=1&&user=" + user + "\">Sửa</a></td> ";
                        chuoi += "<td  style=\"text-align:right\"><a href=\"/Admin/Delete?type=6&&id=" + a.FishID + "&&name=&&user=" + user + "\">Xóa</a></td> ";
                        chuoi += "</tr> ";
                        i++;
                    }
                }


            }
            ID_VIEW = id_View;
            EVI = evi;
            ViewBag.body = chuoi;
            return View();

        }

        public static int ID_VIEW { get; set; }
        static int EVI;

        [HttpPost]

        public ActionResult ListView(FormCollection collection)
        {

            int sss = int.Parse(collection["luachon"]);
            return RedirectToAction("ListView", new { evi = EVI, id_View = ID_VIEW, ttd = sss , user = USER});
        }
        #endregion
        #region[Delete]

        static bool isdelete = true;
        public ActionResult Delete(int type, int id, string name ,string user )
        {
            if (isdelete == false)
            {
                ViewBag.thongbaoloi = "Cần chắc chắn rằng thành phần bạn muốn xóa không chứa bất kì một thành phần con nào! ";
                isdelete = true;         
            }
            ViewBag.l1a = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
            ViewBag.l1b = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
            ViewBag.l1c = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
            ViewBag.l1d = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
            ViewBag.l1e = "/Admin/AddPCOFG?id_each=-1&&id_all=5&&user=" + user;
            ViewBag.l1f = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.l2 = "/Admin/AddFish?id_fi=-1&&user=" + user;

            ViewBag.l3 = "/Admin/ChangInfo?user=" + user;
            ViewBag.l4 = "/Admin/ChangeInfo?user=" + user;

            ViewBag.l5 = "/Admin/ListView?evi=-1&&id_View=1&&ttd=1&&user=" + user;
            ViewBag.l6 = "/Admin/ListView?evi=-1&&id_View=2&&ttd=1&&user=" + user;
            ViewBag.l7 = "/Admin/ListView?evi=-1&&id_View=3&&ttd=1&&user=" + user;
            ViewBag.l8 = "/Admin/ListView?evi=-1&&id_View=4&&ttd=1&&user=" + user;
            ViewBag.l9 = "/Admin/ListView?evi=-1&&id_View=5&&ttd=1&&user=" + user;
            ViewBag.l10 = "/Admin/ListView?evi=-1&&id_View=6&&ttd=1&&user=" + user;


            ViewBag.l13 = "/Admin/ListView?evi=3&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l14 = "/Admin/ListView?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l15 = "/Admin/ListView?evi=1&&id_View=-1&&ttd=1&&user=" + user;

            ViewBag.l16 = "/Admin/MainAdmin?user=" + user;

            ViewBag.l17 = "/Admin/Poster?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l18 = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.AdminName = user;




            switch (type)
            {
                case 0:
                    {
                        var x = (from _x in db.Posters where _x.name == name select _x);
                        ViewBag.thongbao = "Bạn muốn xóa tài khoản người viết bài tên: " + x.First().name + "?";
                        ViewBag.linkback = "/Admin/Poster";
                        break;
                    }
                case 1:
                    {
                        var x = (from _x in db.Phyla where _x.PhylumID == id select _x);
                        ViewBag.thongbao = "Bạn muốn xóa Ngành: " + x.First().PhylumName + "?";
                        ViewBag.linkback = "/Admin/ListView?evi=-1&&id_View=" + type + "&&ttd=1&&user=" + user + "";

                        break;
                    }
                case 2:
                    {
                        var x = (from _x in db.ClassFish where _x.ClassID == id select _x);
                        ViewBag.thongbao = "Bạn muốn xóa lớp: " + x.First().ClassName + "?";
                        ViewBag.linkback = "/Admin/ListView?evi=-1&&id_View=" + type + "&&ttd=1&&user=" + user + "";

                        break;
                    }
                case 3:
                    {
                        var x = (from _x in db.Ordoes where _x.OrdoID == id select _x);
                        ViewBag.thongbao = "Bạn muốn xóa Bộ: " + x.First().OrdoName + "?";
                        ViewBag.linkback = "/Admin/ListView?evi=-1&&id_View=" + type + "&&ttd=1&&user=" + user + "";
                        break;
                    }
                case 4:
                    {
                        var x = (from _x in db.Familias where _x.FamiliaID == id select _x);
                        ViewBag.thongbao = "Bạn muốn xóa Họ: " + x.First().FamilialName + "?";
                        ViewBag.linkback = "/Admin/ListView?evi=-1&&id_View=" + type + "&&ttd=1&&user=" + user + "";

                        break;
                    }
                case 5:
                    {
                        var x = (from _x in db.Genus where _x.GenusID == id select _x);
                        ViewBag.thongbao = "Bạn muốn xóa chi: " + x.First().GenusName + "?";
                        ViewBag.linkback = "/Admin/ListView?evi=-1&&id_View=" + type + "&&ttd=1&&user=" + user + "";

                        break;

                    }
                case 6:
                    {
                        var x = (from _x in db.Fish where _x.FishID == id select _x);
                        ViewBag.thongbao = "Bạn muốn xóa loài cá : " + x.First().FishName + "?";
                        ViewBag.linkback = "/Admin/ListView?evi=-1&&id_View=" + type + "&&ttd=1&&user=" + user + "";

                        break;
                    }
                default: { break; }
            }
                           
            PTYPE = type;
            PID = id;
            PNAME = name;
            USER = user;
            return View();
        }

       
        static int PTYPE;
        static int PID;
        static string PNAME;
       
        [HttpPost]

        public ActionResult Delete(FormCollection collection)
        {
            switch (PTYPE)
            {
                case 0:
                    {
                        Poster a = (from _a in db.Posters where _a.name == PNAME select _a).ToList().First();
                        db.Posters.Remove(a);
                        db.SaveChanges();
                        return RedirectToAction("Poster", new { user = USER });
                    }
                case 1:
                    {
                        Phylum a = (from _a in db.Phyla where _a.PhylumID == PID select _a).ToList().First();
                        try
                        {
                            db.Phyla.Remove(a);
                            db.SaveChanges();
                            return RedirectToAction("ListView", new { evi = -1, id_View = 1, ttd = 1, user = USER });
                   
                        }
                        catch
                        {
                            isdelete = false;
                            
                            return RedirectToAction("Delete", new { type = 1, id = PID, name = PNAME, user = USER});
                        }
                       
                         }
                case 2:
                    {
                        ClassFish a = (from _a in db.ClassFish where _a.ClassID == PID select _a).ToList().First();
                        try
                        {
                            db.ClassFish.Remove(a);
                            db.SaveChanges();
                        }
                        catch
                        {
                            isdelete = false;
                            return RedirectToAction("Delete", new { type =2, id = PID, name = PNAME, user = USER });
                        }
                        return RedirectToAction("ListView", new { evi = -1, id_View = 2, ttd = 1, user = USER });
                    }
                case 3:
                    {
                        Ordo a = (from _a in db.Ordoes where _a.OrdoID == PID select _a).ToList().First();
                        try
                        {
                            db.Ordoes.Remove(a);
                            db.SaveChanges();

                        }
                        catch
                        {
                            isdelete = false;
                            return RedirectToAction("Delete", new { type = 3, id = PID, name = PNAME, user = USER });
                       
                        }
                       return RedirectToAction("ListView", new { evi = -1, id_View = 3, ttd = 1, user = USER });
                    }
                case 4:
                    {
                        Familia a = (from _a in db.Familias where _a.FamiliaID == PID select _a).ToList().First();
                        try
                        {
                            db.Familias.Remove(a);
                            db.SaveChanges();
                        }
                        catch
                        {
                            isdelete = false;
                            return RedirectToAction("Delete", new { type = 4, id = PID, name = PNAME, user = USER });
                       
                        }
                            return RedirectToAction("ListView", new { evi = -1, id_View = 4, ttd = 1, user = USER });
                    }
                case 5:
                    {
                        Genu a = (from _a in db.Genus where _a.GenusID == PID select _a).ToList().First();
                        try
                        {
                            db.Genus.Remove(a);
                            db.SaveChanges();
                        }
                        catch
                        {
                            isdelete = false;
                            return RedirectToAction("Delete", new { type =5, id = PID, name = PNAME, user = USER });
                       
                        }
                            return RedirectToAction("ListView", new { evi = -1, id_View = 5, ttd = 1, user = USER });
                    }
                case 6:
                    {
                        Fish a = (from _a in db.Fish where _a.FishID == PID select _a).ToList().First();
                        try
                        {
                            db.Fish.Remove(a);
                            db.SaveChanges();
                        }
                        catch
                        {
                            isdelete = false;
                            return RedirectToAction("Delete", new { type = 6, id = PID, name = PNAME, user = USER });
                       
                        }
                            return RedirectToAction("ListView", new { evi = -1, id_View = 6, ttd = 1, user = USER });
                    }
                default:
                    {
                        
                        return View();
                    }
            }
            
        }

        #endregion
        #region[Poster]

        public ActionResult Poster(string user)
        {
            ViewBag.l1a = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
            ViewBag.l1b = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
            ViewBag.l1c = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
            ViewBag.l1d = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
            ViewBag.l1e = "/Admin/AddPCOFG?id_each=-1&&id_all=5&&user=" + user;
            ViewBag.l1f = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.l2 = "/Admin/AddFish?id_fi=-1&&user=" + user;

            ViewBag.l3 = "/Admin/ChangInfo?user=" + user;
            ViewBag.l4 = "/Admin/ChangeInfo?user=" + user;

            ViewBag.l5 = "/Admin/ListView?evi=-1&&id_View=1&&ttd=1&&user=" + user;
            ViewBag.l6 = "/Admin/ListView?evi=-1&&id_View=2&&ttd=1&&user=" + user;
            ViewBag.l7 = "/Admin/ListView?evi=-1&&id_View=3&&ttd=1&&user=" + user;
            ViewBag.l8 = "/Admin/ListView?evi=-1&&id_View=4&&ttd=1&&user=" + user;
            ViewBag.l9 = "/Admin/ListView?evi=-1&&id_View=5&&ttd=1&&user=" + user;
            ViewBag.l10 = "/Admin/ListView?evi=-1&&id_View=6&&ttd=1&&user=" + user;


            ViewBag.l13 = "/Admin/ListView?evi=3&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l14 = "/Admin/ListView?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l15 = "/Admin/ListView?evi=1&&id_View=-1&&ttd=1&&user=" + user;

            ViewBag.l16 = "/Admin/MainAdmin?user=" + user;

            ViewBag.l17 = "/Admin/Poster?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l18 = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.AdminName = user;

            string chuoi = "";
            var AllPoster = (from _poster in db.Posters select _poster).ToList();
            int i = 1;
            foreach (Poster p in AllPoster)
            {
                chuoi += "<tr style=\"height:35px;\">";
                chuoi += "<td>"+i+"</td>";
                chuoi += "<td style=\"width:300px; text-align:center\">"+p.name+"</td>";
                chuoi += "<td style=\"width:200px; text-align: center\">"+p.pass+"</td>";
                chuoi += "<td style=\"width: 100px; text-align: center\"><a href=\"/Admin/InfoPoster?postername="+p.name+"&&user="+user+"\">Xem thêm</a></td>";
                chuoi += "<td style=\"width: 100px; text-align: center\"><a href=\"/Admin/EditPoster?postername="+p.name+"&&user="+user+"\">Sửa</a></td>";
                chuoi += "<td style=\"width: 100px; text-align: center\"><a href=\"/Admin/Delete?type=0&&id=-1&&name="+p.name+"&&user="+user+"\">Xóa</a></td>"; 
                chuoi += "</tr>";
                i++;
            }

            ViewBag.ds = chuoi;
            return View();
        }

        [HttpPost]
        public ActionResult Poster(FormCollection collection)
        {
            return RedirectToAction("EditPoster", new { postername = "" , user = USER });
        }

        #endregion
        #region[EditPoster]
        public ActionResult EditPoster( string postername, string user)
        {
            ViewBag.l1a = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
            ViewBag.l1b = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
            ViewBag.l1c = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
            ViewBag.l1d = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
            ViewBag.l1e = "/Admin/AddPCOFG?id_each=-1&&id_all=5&&user=" + user;
            ViewBag.l1f = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.l2 = "/Admin/AddFish?id_fi=-1&&user=" + user;

            ViewBag.l3 = "/Admin/ChangInfo?user=" + user;
            ViewBag.l4 = "/Admin/ChangeInfo?user=" + user;

            ViewBag.l5 = "/Admin/ListView?evi=-1&&id_View=1&&ttd=1&&user=" + user;
            ViewBag.l6 = "/Admin/ListView?evi=-1&&id_View=2&&ttd=1&&user=" + user;
            ViewBag.l7 = "/Admin/ListView?evi=-1&&id_View=3&&ttd=1&&user=" + user;
            ViewBag.l8 = "/Admin/ListView?evi=-1&&id_View=4&&ttd=1&&user=" + user;
            ViewBag.l9 = "/Admin/ListView?evi=-1&&id_View=5&&ttd=1&&user=" + user;
            ViewBag.l10 = "/Admin/ListView?evi=-1&&id_View=6&&ttd=1&&user=" + user;


            ViewBag.l13 = "/Admin/ListView?evi=3&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l14 = "/Admin/ListView?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l15 = "/Admin/ListView?evi=1&&id_View=-1&&ttd=1&&user=" + user;

            ViewBag.l16 = "/Admin/MainAdmin?user=" + user;

            ViewBag.l17 = "/Admin/Poster?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l18 = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.AdminName = user;

            if (postername != null && postername != "")
            {               
                Poster poster = (from _p in db.Posters where _p.name == postername select _p).ToList().First();
                ViewBag.head = "Thay đổi thông tin";
                ViewData["ten"] = poster.name;
                ViewData["mk"] = poster.pass;
               
            }
            else
            {
                ViewBag.head = "Thêm mới";
                

            }
            USER = user;
            return View();
        }
       
        [HttpPost]

        public ActionResult EditPoster(FormCollection collection)
        {
            string ten = collection["ten"];
            string mk = collection["mk"];
            int phone = int.Parse(collection["dienthoai"]);
            var tim = (from _p in db.Posters where _p.name == ten select _p).ToList();
           
            if (tim.Count == 0)
            {
                Poster a= new Poster();
                a.name = ten;
                a.pass = mk;
                a.admin = false;
                a.phone = phone;
                a.mail = null;
                a.information = null;
                a.fullname = null;
                db.Posters.Add(a);
                db.SaveChanges();
            }else
            {
                Poster a = tim.First();
                a.pass = mk;
                a.admin = false;
                a.phone = phone;
                UpdateModel(a);
                db.SaveChanges();
            }
            

            return RedirectToAction("Poster", new {user = USER});
        }
        #endregion
        #region[InfoPoster]
        public ActionResult InfoPoster(string postername, string user)
        {
            ViewBag.l1a = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
            ViewBag.l1b = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
            ViewBag.l1c = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
            ViewBag.l1d = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
            ViewBag.l1e = "/Admin/AddPCOFG?id_each=-1&&id_all=5&&user=" + user;
            ViewBag.l1f = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.l2 = "/Admin/AddFish?id_fi=-1&&user=" + user;

            ViewBag.l3 = "/Admin/ChangInfo?user=" + user;
            ViewBag.l4 = "/Admin/ChangeInfo?user=" + user;

            ViewBag.l5 = "/Admin/ListView?evi=-1&&id_View=1&&ttd=1&&user=" + user;
            ViewBag.l6 = "/Admin/ListView?evi=-1&&id_View=2&&ttd=1&&user=" + user;
            ViewBag.l7 = "/Admin/ListView?evi=-1&&id_View=3&&ttd=1&&user=" + user;
            ViewBag.l8 = "/Admin/ListView?evi=-1&&id_View=4&&ttd=1&&user=" + user;
            ViewBag.l9 = "/Admin/ListView?evi=-1&&id_View=5&&ttd=1&&user=" + user;
            ViewBag.l10 = "/Admin/ListView?evi=-1&&id_View=6&&ttd=1&&user=" + user;


            ViewBag.l13 = "/Admin/ListView?evi=3&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l14 = "/Admin/ListView?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l15 = "/Admin/ListView?evi=1&&id_View=-1&&ttd=1&&user=" + user;

            ViewBag.l16 = "/Admin/MainAdmin?user=" + user;

            ViewBag.l17 = "/Admin/Poster?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l18 = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.AdminName = user;

            try
            {
                Poster a = (from _a in db.Posters where _a.name == postername select _a).ToList().First();
                ViewBag.ten = a.name;
                ViewBag.mk = a.pass;
                ViewBag.tenfull = a.fullname;
                ViewBag.phone = a.phone;
                ViewBag.mail = a.mail;
                ViewBag.tt = a.information;
                if (a.admin == true) { ViewBag.phanquyen = "Admin"; }
                else { ViewBag.phanquyen = "Poster"; }                                   
            }
            catch
            {
                ViewBag.error = "Xảy ra lỗi hệ thống, Quay lại sau ít phút!";
            }
            return View();
        }
        #endregion
        #region[ChangeInfo]
        public ActionResult ChangeInfo(string user)
        {
            ViewBag.l1a = "/Admin/AddPCOFG?id_each=-1&&id_all=1&&user=" + user;
            ViewBag.l1b = "/Admin/AddPCOFG?id_each=-1&&id_all=2&&user=" + user;
            ViewBag.l1c = "/Admin/AddPCOFG?id_each=-1&&id_all=3&&user=" + user;
            ViewBag.l1d = "/Admin/AddPCOFG?id_each=-1&&id_all=4&&user=" + user;
            ViewBag.l1e = "/Admin/AddPCOFG?id_each=-1&&id_all=5&&user=" + user;
            ViewBag.l1f = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.l2 = "/Admin/AddFish?id_fi=-1&&user=" + user;

            ViewBag.l3 = "/Admin/ChangInfo?user=" + user;
            ViewBag.l4 = "/Admin/ChangeInfo?user=" + user;

            ViewBag.l5 = "/Admin/ListView?evi=-1&&id_View=1&&ttd=1&&user=" + user;
            ViewBag.l6 = "/Admin/ListView?evi=-1&&id_View=2&&ttd=1&&user=" + user;
            ViewBag.l7 = "/Admin/ListView?evi=-1&&id_View=3&&ttd=1&&user=" + user;
            ViewBag.l8 = "/Admin/ListView?evi=-1&&id_View=4&&ttd=1&&user=" + user;
            ViewBag.l9 = "/Admin/ListView?evi=-1&&id_View=5&&ttd=1&&user=" + user;
            ViewBag.l10 = "/Admin/ListView?evi=-1&&id_View=6&&ttd=1&&user=" + user;


            ViewBag.l13 = "/Admin/ListView?evi=3&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l14 = "/Admin/ListView?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l15 = "/Admin/ListView?evi=1&&id_View=-1&&ttd=1&&user=" + user;

            ViewBag.l16 = "/Admin/MainAdmin?user=" + user;

            ViewBag.l17 = "/Admin/Poster?evi=2&&id_View=-1&&ttd=1&&user=" + user;
            ViewBag.l18 = "/Admin/EditPoster?postername=&&user=" + user;
            ViewBag.AdminName = user;

            var Post = (from _post in db.Posters where _post.name == user select _post).ToList();
            Poster poster = new Poster();
            poster = Post.First();
            ViewBag.name = user;
            ViewData["fullname"] = poster.fullname;
            ViewData["phonenumber"] = poster.phone;
            ViewData["email"] = poster.mail;
            ViewData["infomation"] = poster.information;
            USER = user;
            return View();
        }

        [HttpPost]

        public ActionResult ChangeInfo(FormCollection collection)
        {
            Poster poster = new Poster();
            poster = (from p in db.Posters where p.name == USER select p).ToList().First();
            poster.fullname = collection["fullname"];
            poster.phone = int.Parse(collection["phonenumber"]);
            poster.mail = collection["email"];
            poster.information = collection["information"];

            UpdateModel(poster);
            db.SaveChanges();

            return RedirectToAction("MainPoster", new { user = USER });

        }
        #endregion

    }
}
